<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<div th:replace="admin/module/_header"></div>

<div class="wrapper">
    <div th:replace="admin/module/_sidebar"></div>
    <div class="content-wrapper">
        <style type="text/css" rel="stylesheet">

        </style>
        <section class="content-header">
            <h1 style="display: inline-block;">店铺列表</h1>
            <ol class="breadcrumb">
                <li>
                    <a data-pjax="true" href="/admin">
                        <i class="fa fa-dashboard"></i> 首页</a>
                </li>
                <li><a data-pjax="true" href="/store">店铺管理</a></li>
                <li class="active">店铺列表</li>
            </ol>
        </section>
        <section class="content container-fluid">
            <div class="row">
                <div class="col-xs-12">
                    <div class="col-md-4 col-xs-12" style="margin-bottom: 10px;padding-left: 0;">
                        <a th:if="${isAdmin}" class="btn btn-primary" href="/admin/store/add">
                            <i class="fa fa-plus"></i> 添加店铺
                        </a>
                        <button  th:if="${isAdmin}" type="button" class="btn btn-danger" onclick="batchDelete()">
                            <i class="fa fa-remove"></i> 批量删除
                        </button>
                    </div>
                    <div class="col-md-8 col-xs-12"
                         style="margin-bottom: 10px; text-align:right;padding-left: 0; padding-right: 0;">
                        <form class="form-inline" action="/admin/ad/store">
                            <div class="form-group">
                                <input type="text" class="form-control" id="keywords" name="keywords"
                                       th:value="${keywords}" placeholder="请输入店铺名称关键字">
                            </div>
                            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i> 搜索</button>
                        </form>
                    </div>
                </div>
                <div class="col-xs-12">
                    <div class="box box-primary">
                        <div class="box-body table-responsive">
                            <table class="table table-bordered table-hover">
                                <thead>
                                <tr>
                                    <th class="col-md-1">
                                        <input type="checkbox" id="allSelect" onclick="doCheck()">
                                    </th>
                                    <th>店铺照片</th>
                                    <th>店铺名称</th>
                                    <th>责任人姓名</th>
                                    <th>责任人手机号</th>
                                    <th>责任人用户账号</th>
                                    <th class="col-md-2">操作</th>
                                    <th class="col-md-1">ID</th>
                                </tr>
                                </thead>
                                <tbody>
                                <tr th:each="item : ${dataList}">
                                    <td>
                                        <input type="checkbox" name="ids" th:value="${item.id}">
                                    </td>
                                    <td>
                                        <a th:href="'/store/detail?id='+${item.id}" target="_blank">
                                            <img th:src="${item.photo}" style="width: 100px;height: 100px;" alt="">
                                        </a>
                                    </td>
                                    <td>
                                        <a th:href="'/store/'+${item.id}" target="_blank">[[${item.name}]]</a>
                                    </td>
                                    <td>
                                        <span>[[${item.businessName}]]</span>
                                    </td>
                                    <td>
                                        <span>[[${item.businessPhone}]]</span>
                                    </td>
                                    <td>
                                        <a href="'/admin/user/edit?id='+${item.user.id}">
                                            [[${item.user.userDisplayName}]]
                                        </a>
                                    </td>
                                    <td>
                                        <a  href="javascript:void(0)" th:onclick="'cancelRecommend('+${item.id}+')'"
                                           class="btn btn-danger btn-xs">取消推荐</a>
                                    </td>
                                    <td>
                                        <a th:href="'/admin/store/detail?id='+${item.id}">[[${item.id}]]</a>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>
                        <div class="box-footer clearfix">
                            <div class="no-margin pull-left">
                                第 [[${pageInfo.current}]] / [[${pageInfo.pages}]] 页
                            </div>
                            <ul class="pagination no-margin pull-right">
                                <li><a data-pjax="true" th:classappend="${pageInfo.current == 1 ? 'disabled' : ''}"
                                       class="btn btn-sm"
                                       th:href="'?keywords='+${keywords}">
                                    首页
                                </a>
                                </li>
                                <li><a data-pjax="true" class="btn btn-sm"
                                       th:classappend="${pageInfo.current == 1 ? 'disabled' : ''}"
                                       th:href="'?page='+${pageInfo.current-1}+'&keywords='+${keywords}">
                                    上一页
                                </a>
                                </li>
                                <li><a data-pjax="true" class="btn btn-sm"
                                       th:classappend="${pageInfo.current >= pageInfo.pages ? 'disabled' : ''}"
                                       th:href="'?page='+${pageInfo.current+1}+'&keywords='+${keywords}">
                                    下一页
                                </a>
                                </li>
                                <li><a data-pjax="true" class="btn btn-sm"
                                       th:classappend="${pageInfo.current >= pageInfo.pages ? 'disabled' : ''}"
                                       th:href="'?page='+${pageInfo.pages}+'&keywords='+${keywords}">
                                    尾页
                                </a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <script>

            function removeIt(id) {
                layer.confirm("你确定是否删除？", function (index) {
                    $.ajax({
                        type: "POST",
                        url: '/admin/store/delete',
                        async: false,
                        data: {
                            'id': id
                        },
                        success: function (data) {
                            if (data.code == 0) {
                                showMsg(data.msg, "error", 2000);
                            } else {
                                showMsgAndReload(data.msg, "success", 1000);
                            }

                        }
                    });
                    layer.close(index);
                });
            }


            function batchDelete() {
                var arr = [];
                $('input[name="ids"]:checked').each(function () {
                    arr.push($(this).val());
                });
                if (arr.length <= 0) {
                    showMsg('请选择要删除的记录', "error", 2000);
                } else {
                    layer.confirm('你确定是否删除?', function (index) {
                        $.ajax({
                            url: "/admin/store/batchDelete?ids=" + arr,
                            type: "POST",
                            success: function (data) {
                                if (data.code == 0) {
                                    showMsg(data.msg, "error", 2000);
                                } else {
                                    showMsgAndReload(data.msg, "success", 1000);
                                }
                            }
                        });
                        layer.close(index);
                    });
                }
            }

            function cancelRecommend(id) {
                layer.confirm("你确定取消推荐该店铺？", function (index) {
                    $.ajax({
                        type: "POST",
                        url: '/admin/store/closeStoreRecommend',
                        async: false,
                        data: {
                            'id': id
                        },
                        success: function (data) {
                            if (data.code == 0) {
                                showMsg(data.msg, "error", 2000);
                            } else {
                                showMsgAndReload(data.msg, "success", 1000);
                            }

                        }
                    });
                    layer.close(index);
                });
            }


        </script>
    </div>
</div>
<div th:replace="admin/module/_footer"></div>

